import { createRouter, createWebHashHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

// Layouts
import Layout from '@/components/layout/Layout.vue'

// Views
import Dashboard from '@/views/dashboard/Dashboard.vue'
import Login from '@/views/login/Login.vue'
import Profile from '@/views/profile/Profile.vue'

// Device Management
import DeviceList from '@/views/devices/DeviceList.vue'
import DeviceLogs from '@/views/devices/DeviceLogs.vue'

// User Management
import UserList from '@/views/users/UserList.vue'
import UserDetail from '@/views/users/UserDetail.vue'

// Treatment Management
import TreatmentList from '@/views/treatments/TreatmentList.vue'
import TreatmentAnalysis from '@/views/treatments/TreatmentAnalysis.vue'
import TreatmentTemplates from '@/views/treatments/TreatmentTemplates.vue'
import MusicManagement from '@/views/treatments/MusicManagement.vue'  // 替换为音乐管理页面

// System Management
import SystemSettings from '@/views/system/SystemSettings.vue'
import SystemLogs from '@/views/system/SystemLogs.vue'
import SystemBackup from '@/views/system/SystemBackup.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: Dashboard,
        meta: { title: '仪表板', icon: 'House' }
      }
    ]
  },
  
  // Device Management
  // {
  //   path: '/devices',
  //   component: Layout,
  //   meta: { title: '设备管理', icon: 'Monitor' },
  //   children: [
  //     {
  //       path: '',
  //       name: 'DeviceList',
  //       component: DeviceList,
  //       meta: { title: '设备列表' }
  //     },
  //     {
  //       path: 'logs/:deviceId',
  //       name: 'DeviceLogs',
  //       component: DeviceLogs,
  //       meta: { title: '设备日志' },
  //       props: true
  //     }
  //   ]
  // },
  
  // User Management
  {
    path: '/users',
    component: Layout,
    meta: { title: '用户管理', icon: 'User' },
    children: [
      {
        path: '',
        name: 'UserList',
        component: UserList,
        meta: { title: '用户列表' }
      },
      {
        path: ':id',
        name: 'UserDetail',
        component: UserDetail,
        meta: { title: '用户详情', hidden: true },
        props: true
      }
    ]
  },
  
  // Treatment Management
  {
    path: '/treatments',
    component: Layout,
    meta: { title: '治疗管理', icon: 'FirstAidKit' },
    children: [
      {
        path: 'list',
        name: 'TreatmentList',
        component: TreatmentList,
        meta: { title: '治疗记录' }
      },
      // {
      //   path: 'analysis',
      //   name: 'TreatmentAnalysis',
      //   component: TreatmentAnalysis,
      //   meta: { title: '治疗分析' }
      // },
      {
        path: 'templates',
        name: 'TreatmentTemplates',
        component: TreatmentTemplates,
        meta: { title: '治疗模板' }
      },
      {
        path: 'music',  // 替换音乐模板路由为音乐管理
        name: 'MusicManagement',
        component: MusicManagement,
        meta: { title: '音乐管理' }
      }
    ]
  },
  
  // System Management
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'Setting' },
    children: [
      // {
      //   path: 'settings',
      //   name: 'SystemSettings',
      //   component: SystemSettings,
      //   meta: { title: '系统设置' }
      // },
      {
        path: 'logs',
        name: 'SystemLogs',
        component: SystemLogs,
        meta: { title: '系统日志' }
      },
      // {
      //   path: 'backup',
      //   name: 'SystemBackup',
      //   component: SystemBackup,
      //   meta: { title: '数据备份' }
      // }
    ]
  },
  
  // Auth
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { title: '登录' }
  },
  
  // Profile
  {
    path: '/profile',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Profile',
        component: Profile,
        meta: { title: '个人中心' }
      }
    ]
  },
  
  // 404
  {
    path: '/:pathMatch(.*)*',
    name: '404',
    component: () => import('@/views/error/404.vue'),
    meta: { title: '页面未找到' }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router